/*! ******************************************************************************
 *
 * Created on 2021年11月29日
 *
 * Copyright(c) YuZhou Big Data Laboratory CO.,Ltd, 2022.  All rights reserved.
 *
 *******************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************/

package org.pentaho.di.ui.spoon.navigation.view;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.pentaho.di.ui.core.gui.GUIResource;
import org.pentaho.di.ui.core.widget.TreeMemory;
import org.pentaho.di.ui.spoon.Spoon;
import org.pentaho.di.ui.spoon.navigation.SpoonRef;

/**
 * 主对象类别抽象父类
 * 
 * @author hs@yzbdl.ac.cn
 *
 */
public abstract class CategoryTree {

    /**
     * 持有对Spoon的引用,
     */
    private SpoonRef spoonRef;

    /**
     * 持有的主对象树引用
     */
    private Tree parent;

    /**
     * 对应的视图
     */
    private TreeItem view;

    public CategoryTree(Spoon spoon, Tree parent) {
        super();
        this.spoonRef = new SpoonRef(spoon);
        this.parent = parent;
        this.view = new TreeItem(parent, SWT.NONE);
        this.view.setText(getName());
        this.view.setImage(GUIResource.getInstance().getImageFolder());

        // Set expanded if this is the only transformation shown.
        if (spoon.props.isOnlyActiveFileShownInTree()) {
            this.view.setExpanded(true);
            TreeMemory.getInstance().storeExpanded(Spoon.STRING_SPOON_MAIN_TREE, this.view, true);
        }
    }

    /**
     * 获取节点名称
     * 
     * @return 节点名称
     */
    public abstract String getName();

    /**
     * 设置展开状态
     * 
     * @param expanded
     *            true展开 false折叠
     */
    public void setExpanded(boolean expanded) {
        this.getView().setExpanded(expanded);
    }

    /**
     * 构建MetaTree节点
     */
    public abstract MetaTree buildMetaTree();

    public SpoonRef getSpoonRef() {
        return spoonRef;
    }

    public void setSpoonRef(SpoonRef spoonRef) {
        this.spoonRef = spoonRef;
    }

    public Tree getParent() {
        return parent;
    }

    public void setParent(Tree parent) {
        this.parent = parent;
    }

    public TreeItem getView() {
        return view;
    }

    public void setView(TreeItem view) {
        this.view = view;
    }

}
